<%@ page language="java" import="java.util.*,cn.sypt.yuhao.model.*" pageEncoding="utf-8"%>
<%@taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/ui/";

   UserBean user=(UserBean)session.getAttribute("user");
   boolean loginFlag=false; //false表示没有登录
   if(user !=null)
   {
      loginFlag=true;
   }

%>
<!DOCTYPE HTML>
<html>
<head>
<title>Register</title>
<base href="<%=basePath%>">
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery.min.js"></script>
<!-- Custom Theme files -->
<!--theme-style-->
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />	
<!--//theme-style-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="New Store Responsive web template, Bootstrap Web Templates, Flat Web Templates, Andriod Compatible web template, 
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!--fonts-->
<!-- start menu -->
<link href="css/memenu.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="js/memenu.js"></script>
<script>$(document).ready(function(){$(".memenu").memenu();});</script>
<script src="js/simpleCart.min.js"> </script>
<script type="text/javascript">
$(document).ready(function(){
	$("#uemail").blur(function(){
		var email=$("#uemail").val();
		$.ajax({
			type : "POST",
			url : "/sypt/UserServlet",
			async : false,
			dataType : "text",
			data : {
				"method" : "ajaxEmail",
				"email" : email,
				
			},
			success : function(data) {
				if(data!=1){
					alert(data);
				};
			}
		});
	})
	
	$("#uname").blur(function(){
		var uname=$("#uname").val();
		
		$.ajax({
			type : "POST",
			url : "/sypt/UserServlet",
			async : false,
			dataType : "text",
			data : {
				"method" : "ajaxUser",
				"uname" : uname,
				
			},
			success : function(data) {
				if(data!=1){
					alert(data);
				};
			}
		});
	});
	
})


</script>
<script language="javascript" src="js/trim.js"></script>
    <script language="javascript">
    
    function checkSub()
      {
      	var flag = false;
      	var cname = aform.uname.value;
      	var cpassword = aform.upass.value;
      	var spw = aform.spass.value;
      	var uemail = aform.uemail.value;
      	var uphone = aform.uphone.value;
      	var ubirth = aform.ubirth.value;
      	var zzb=/^[1|2][9|0][0-9][0-9]-[0|1][0-9]-[0-3][0-9]$/;
      	var zzp=/^1[3|4|5|8][0-9]\d{8}$/;
      	var zzs=/^[a-z0-9A-Z]{6,15}$/;

      	if(cname.trim()=="")
      	{
      	    
      		window.alert("用户名不能为空");
      	}
      	else if(cpassword.trim()=="")
      	{
      		window.alert("密码不能为空");
      	}
      	else if(!zzs.test(cpassword))
      	{
      		window.alert("您设置的密码有误，请重新设置你的密码");
      				
      	}
      	else if(spw.trim()=="")
      	{
      		window.alert("确认密码不能为空");
      	}
        else if(spw.trim()!=cpassword.trim())
      	{
      		window.alert("两次密码输入不一致");
      	}
      	else if(uemail.trim()=="")
      	{
      		window.alert("邮箱不能为空");
      	}
      	else if(ubirth.trim()=="")
      	{
      	    window.alert("出生年月不能为空");
      	}
      	else if(uphone.trim()=="")
      	{
            window.alert("电话不能空");      	
      	}
      	else if(!zzb.test(ubirth))
      	{
      	    window.alert("格式有误请填写你的出生年月");
      	}
      	else if(!zzp.test(uphone))
      	{
      	    window.alert("格式有误请填写你的手机号码");
      	}
      	
      	
        else
      	{
      		flag = true;
		
      	}
      	return flag;
      }

    
    
    </script>

</head>
  
  
  
  <body>
  <jsp:include flush="true" page="head.jsp"></jsp:include>
   <div class=" container">
<div class=" register">
	<h1>注册</h1>
		  	  <form action="<c:url value='/UserServlet?method=regist'/>" name="aform" method="post"> 
				 <div class="col-md-6 register-top-grid">
					<h3>个人信息</h3>
					 <div>
						<span>Email地址</span>
						
						<input type="text" id="uemail" name="uemail" <%=loginFlag?"disabled":""%>/> 
						<td id="einfo" width="400"><font color="blue" size="2px">请输入符合格式的邮箱地址。</font></td>
					 </div>
					 <div>
						 <span>住址</span>
						 <input type="text" name="uaddress"> 
					 </div>
					  <div>
						 <span>出生年月</span>
						 <input type="text" name="ubirth" id="ubirth">
						 <td id="spinfo" width="400"><font color="blue" size="2px">8位年-月-日的数字组合例如:1995-01-08</font></td> 
					 </div>
					  <div>
						 <span>电话</span>
						 <input type="text" name="uphone" id="uphone">
						 <td width="400"><font color="blue" size="2px">11位的手机号码</font></td> 
					 </div>
					   <a class="news-letter" href="#">
						 <label class="checkbox"><input type="checkbox" name="checkbox" checked=""><i> </i>Sign Up for Newsletter</label>
					   </a>
					 </div>
				     <div class="col-md-6 register-bottom-grid">
						    <h3>登录信息</h3>
						    <div>
								<span>用户名</span>
								<input type="text" id="uname" name="uname" onblur="checkCname"<%=loginFlag?"disabled":""%>>
								<td id="uinfo" width="400"><font color="blue" size="2px">用户名可以由小写英文字母、中文、数字组成。</font></td>
							 </div>
							 <div>
								<span>密码</span>
								<input type="password" name="upass" id="upass" onblur="checkCpw" <%=loginFlag?"disabled":""%>>
								<td id="pinfo" width="400"><font color="blue" size="2px">密码可以由小写英文字母、数字组成，要大于6位小于15位。</font></td>
							 </div>
							 <div>
								<span>确认密码</span>
								<input type="password" name="spass" id="spass" onblur="checkSpw" <%=loginFlag?"disabled":""%>>
							    <td id="spinfo" width="400"><font color="blue" size="2px">密码可以由小写英文字母、数字组成，要大于6位小于15位。</font></td>
							 </div>
							 <input type="submit" value="注册" onclick="return checkSub();" style="cursor:hand"/>
							 
							
							
					 </div>
					 <div class="clearfix"> </div>
				</form>
			</div>
</div>

<jsp:include flush="true" page="foot.jsp"></jsp:include>
  </body>
  <script>
  <% 
    if(loginFlag)
    {
  %>
     alert("已经登录的情况下不可以注册新用户，\n请注销后再执行此操作！");
  <%
    }
   %>
</script>
<script>
   <% 
     String msg=(String)request.getAttribute("msg");
     if(msg!=null)
     {
   %>
     alert('<%=msg%>');
   <%     
     }
   %>
</script>
</html>
